package com.github.postsanf.yinian.adapter;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.github.postsanf.yinian.R;
import com.github.postsanf.yinian.utils.DisplayUtils;
import com.github.postsanf.yinian.utils.ImageOptHelper;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

/**
 * Created by Administrator on 2016/9/11.
 */
public class LoMoPreViewAdapter extends BaseAdapter {

    private List<String> itemPic;
    private Context mContext;
    private LayoutInflater mInflater;

    public LoMoPreViewAdapter(Context mContext, List<String> itemPic) {
        mInflater = LayoutInflater.from(mContext);
        this.itemPic = itemPic;
        this.mContext = mContext;
    }

    @Override
    public int getCount() {
        return itemPic.size();
    }

    @Override
    public Object getItem(int position) {
        return itemPic.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        convertView = mInflater.inflate(R.layout.lomo_item_preview, parent, false);
        ImageView iv_lomo_bitmap = ((ImageView) convertView.findViewById(R.id.iv_lomo_bitmap));
        ImageView ll_bg = ((ImageView) convertView.findViewById(R.id.ll_bg));

        int screenWidth_bg = DisplayUtils.getScreenWidthPixels((Activity) mContext);
        int horizontalSpacing_bg = DisplayUtils.dp2px(mContext, 15 + 15 + 24);
        int itemWidth_bg = (screenWidth_bg - horizontalSpacing_bg) / 2;
        RelativeLayout.LayoutParams params_bg = new RelativeLayout.LayoutParams(itemWidth_bg, (int) (itemWidth_bg * 1.2));
        ll_bg.setLayoutParams(params_bg);

        int screenWidth = DisplayUtils.getScreenWidthPixels((Activity) mContext);
        int horizontalSpacing = DisplayUtils.dp2px(mContext, 9);
        int itemWidth = (itemWidth_bg);
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(itemWidth, itemWidth);
        iv_lomo_bitmap.setLayoutParams(params);
        ImageOptHelper.showImageLoaderLoMoPreView(itemPic.get(position) + "?imageView2/2/w/150",iv_lomo_bitmap,mContext);
        return convertView;
    }
}
